class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        # # 去除空格并将字符串转换为小写（如果需要忽略大小写）
        # s = s.lower()
        # cleaned_s = ''.join(c.lower() for c in s if (c >='a' and c <='z') or (c>='0' and c<='9'))
        # # 获取字符串长度
        # length = len(cleaned_s)
        # # 比较前半部分和反转后的后半部分
        # for i in range(length // 2):
        #     if cleaned_s[i] != cleaned_s[length - 1 - i]:
        #         return False
        # return True

        # 双指针
        exp = "".join(ch.lower() for ch in s if ch.isalnum())
        n = len(exp)
        left,right = 0,n-1
        while left < right:
            if exp[left] != exp[right]:
                return False
            left,right = left+1,right-1
        return True
example = Solution()
s = "0P"
print(example.isPalindrome(s))

